using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Chili.Opf3.Wizard.Shared;

namespace Chili.Opf3.Wizard.SimplePlugin
{
	/// <summary>
	/// This class holds the state of the plugin.
	/// </summary>
	public sealed class StateBag
	{
        private string _name;

		/// <summary>
		/// Specifies the name of the user.
		/// </summary>
		public string Name
		{
            get { return _name; }
			set { _name = value; }
		}

        /// <summary>
        /// Serialize the StateBag state to a valid xml.
        /// </summary>
        public XmlNode Serialize(XmlDocument xml)
        {
			// Create the statebag xml element.
            XmlElement statebag = xml.CreateElement("statebag");
			
			// Create the name xml element.
			XmlElement name = xml.CreateElement("name");
			name.AppendChild(xml.CreateTextNode(this.Name));

			// Add the name xml element to the statebag.
			statebag.AppendChild(name);

			return statebag;
        }

        /// <summary>
        /// Deserialize the StateBag from xml.
        /// </summary>
		/// <param name="d">Specifies the node that holds the statebag's data.</param>
        public void Deserialize(XmlNode d)
        {
            XmlNode p = d.SelectSingleNode("./statebag");

            if (p != null)
                this.Name = p.SelectSingleNode("./name").InnerText;
        }
	}
}
